const plugin = requirePlugin('xlightPlugin'); // 引入插件的实例
Component({
	data() {
		return {
			interstitialAd: null,
			spaceCode: '50_2023112825000072251'
		}
	},
	props: {
		onAdLoad: () => {},
		onClose: () => {},
		onAdError: () => {},
		onSuccess: () => {},
	},
	onInit() {
		// 实例化
		const interstitialAd = new plugin.CreateInterstitialAd();
		// 将实例放入data中
		this.setData({
			interstitialAd,
		});

		// 广告插件加载成功
		this.data.interstitialAd.onLoad(() => {
			this.props.onAdLoad(interstitialAd, this.data.spaceCode)
			// 调用show方法，请求广告
			// this.data.interstitialAd.show({
			//   spaceCode: this.data.spaceCode,
			//   rtaExtMap: {},
			// });
		});

		// 广告加载成功
		this.data.interstitialAd.onSuccess(() => {
			this.props.onSuccess()
		});

		// 广告关闭
		this.data.interstitialAd.onClose(() => {
			this.props.onClose()
		});

		// 广告加载失败
		this.data.interstitialAd.onError((err) => {
			this.props.onAdError(err)
		});
	},
});